package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.SwiperimgsDao;
import com.example.wujinapi.dao.UsersDao;
import com.example.wujinapi.entity.Firsttype;
import com.example.wujinapi.entity.Swiperimgs;
import com.example.wujinapi.entity.Users;
import com.example.wujinapi.service.SwiperimgsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Swiperimgs)表服务实现类
 *
 * @author makejava
 * @since 2023-08-25 19:06:34
 */
@Service("swiperimgsService")
public class SwiperimgsServiceImpl extends ServiceImpl<SwiperimgsDao, Swiperimgs> implements SwiperimgsService {


    @Resource
    private SwiperimgsDao swiperimgsDao;

    @Override
    public void addSwiperimgs(Swiperimgs swiperimgs) {
        Swiperimgs smdatas=swiperimgsDao.selectOne(new QueryWrapper<Swiperimgs>().eq("imgtitle",swiperimgs.getImgtitle()).eq("imgurl",swiperimgs.getImgurl()));
        if(smdatas==null){ //为空才插入新数据
            swiperimgsDao.insert(swiperimgs);
        }
    }

    @Override
    public void updateSwiperimgs(Swiperimgs swiperimgs) {
        Swiperimgs smdatas=swiperimgsDao.selectOne(new QueryWrapper<Swiperimgs>().eq("id", swiperimgs.getId()));
        if(smdatas!=null){
            swiperimgs.setId(smdatas.getId());
            swiperimgsDao.updateById(swiperimgs);
        }
    }

    @Override
    public void deleteSwiperimgs(int imgId) {
        swiperimgsDao.delete(new QueryWrapper<Swiperimgs>().eq("id",imgId));
    }

    @Override
    public List<Swiperimgs> getSwiperimgs() {
        List<Swiperimgs> listDatas=swiperimgsDao.selectList(new QueryWrapper<Swiperimgs>().orderByDesc("showindex"));
        return listDatas!=null?listDatas:null;
    }
}

